package com.heima.controller;


import com.heima.pojo.TbVmType;
import com.heima.pojo.dto.TbVmTypeDto;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.TbVmTypeVo;
import com.heima.service.ITbVmTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 售货机类型表 前端控制器
 * </p>
 *
 * @author AkiRinko
 * @since 2024-06-09
 */
@RestController
@RequestMapping("/api/vm-service/vmType")
@RequiredArgsConstructor
public class TbVmTypeController {
    private final ITbVmTypeService tbVmTypeService;

    /**
     * 设备类型搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/search")
    private PageResponse<TbVmTypeVo> selectVmType(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                                  @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "name", required = false) String name) {
        return tbVmTypeService.selectVmType(pageIndex, pageSize, name);
    }

    /**
     * 新增设备类型
     *
     * @param dto
     */
    @PostMapping
    private void insertVmType(@RequestBody TbVmTypeDto dto) {
        tbVmTypeService.insertVmType(dto);
    }

    /**
     * 修改设备类型
     *
     * @param typeId
     * @param dto
     */
    @PutMapping("/{typeId}")
    private void updateVmType(@PathVariable Integer typeId,
                              @RequestBody TbVmTypeDto dto) {
        tbVmTypeService.updateVmType(typeId, dto);
    }

    /**
     * 删除设备类型
     *
     * @param typeId
     */
    @DeleteMapping("/{typeId}")
    private void deleteVmType(@PathVariable Integer typeId) {
        tbVmTypeService.deleteVmType(typeId);
    }
}
